package com.situ.company.controller;



import com.situ.company.entity.User;
import com.situ.company.service.Impl.UserService;
import com.situ.company.service.Impl.service.Impl.UserServiceImpl;
import com.situ.company.vo.ResultVO;
import com.situ.company.vo.TableVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user")
public class UserController extends BaseController{

    UserService service =  new UserServiceImpl();

    //打开页面
    public void page(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //查数据,带上
        req.getRequestDispatcher("/WEB-INF/user.jsp").forward(req,resp);
    }

    public TableVO select(Integer page, Integer limit, String username, String name) {

        //查出来商品的数据
        return service.select(page,limit,username,name);


        //把数据返回给table小工具(响应)
        //获取一个响应的前台写出对象
        //list转完后是[{},{},{}]




    }
    public void save(User u){
        service.save(u);

    }

    public ResultVO delete(Integer id){
        //检查一下是否已经被使用


       return  service.delete(id);
    }


    //编辑
    public  User info(Integer id) {

        return service.info(id);
    }
    //检查用户表中 新增表中用户名格式
    public ResultVO check(String username){
        return service.checkByUsername(username);
    }

    public ResultVO check2(String password){return service.check2(password);}



    //检查修改密码功能 密码是否为当前帐号密码
    public ResultVO checkPassword(String password ,HttpServletRequest req){

        Object currentUser = req.getSession().getAttribute("currentUser");
        String s =(String) currentUser;
        return service.checkPassword(password,s);

    }
    //检查修改密码功能中 两次密码是否输入一致
    public ResultVO resetPassword(String newpassword1 ,String newpassword2,HttpServletRequest req){
        Object currentUser = req.getSession().getAttribute("currentUser");
        String s =(String) currentUser;
        return service.resetPassword(newpassword1,newpassword2,s);
    }
}